Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api] implement web3 API debug_traceTransaction #3779

Merged
merged 16 commits into from
Feb 17, 2023
Merged

[api] implement web3 API debug_traceTransaction #3779

merged 16 commits into from
Feb 17, 2023

Conversation

millken
Copy link
Contributor

@millken millken commented Jan 18, 2023

Description

request:

curl http://127.0.0.1:15014/\
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"debug_traceTransaction","params":["11a23b5aabcd6fe9114f20f75f56a3c951788073618dc168cc2b25bf0e5a9416", {"enableMemory": true,"enableReturnData":true}], "id":1,"jsonrpc":"2.0"}'

response:

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "failed": false,
        "revert": "",
        "returnValue": "0x",
        "gas": 138478,
        "structLogs": [
            ...
            {
                "pc": 2936,
                "op": 162,
                "gas": "0x12f3184",
                "gasCost": "0x2165",
                "memory": "0x",
                "memSize": 2144,
                "stack": [
                    "0x9531dc76",
                    "0x3b8",
                    "0x80",
                    "0x400",
                    "0x5a5dba0be34307952ebd93d284f8df820caa18fa80fbd2d67515fd2804c65cec",
                    "0x462eb2b788a2fc5799f0e0f9f845187bb11fb75150d0fe10a0a932039d8f4ad9",
                    "0x3a0",
                    "0x4c0"
                ],
                "returnData": "0x",
                "storage": null,
                "depth": 1,
                "refund": 0,
                "opName": "LOG2",
                "error": ""
            },
            {
                "pc": 2937,
                "op": 80,
                "gas": "0x12f101f",
                "gasCost": "0x2",
                "memory": "0x",
                "memSize": 2144,
                "stack": [
                    "0x9531dc76",
                    "0x3b8",
                    "0x80",
                    "0x400"
                ],
                "returnData": "0x",
                "storage": null,
                "depth": 1,
                "refund": 0,
                "opName": "POP",
                "error": ""
            },
            {
                "pc": 2938,
                "op": 80,
                "gas": "0x12f101d",
                "gasCost": "0x2",
                "memory": "0x",
                "memSize": 2144,
                "stack": [
                    "0x9531dc76",
                    "0x3b8",
                    "0x80"
                ],
                "returnData": "0x",
                "storage": null,
                "depth": 1,
                "refund": 0,
                "opName": "POP",
                "error": ""
            },
            {
                "pc": 2939,
                "op": 86,
                "gas": "0x12f101b",
                "gasCost": "0x8",
                "memory": "0x",
                "memSize": 2144,
                "stack": [
                    "0x9531dc76",
                    "0x3b8"
                ],
                "returnData": "0x",
                "storage": null,
                "depth": 1,
                "refund": 0,
                "opName": "JUMP",
                "error": ""
            },
            {
                "pc": 952,
                "op": 91,
                "gas": "0x12f1013",
                "gasCost": "0x1",
                "memory": "0x",
                "memSize": 2144,
                "stack": [
                    "0x9531dc76"
                ],
                "returnData": "0x",
                "storage": null,
                "depth": 1,
                "refund": 0,
                "opName": "JUMPDEST",
                "error": ""
            },
            {
                "pc": 953,
                "op": 0,
                "gas": "0x12f1012",
                "gasCost": "0x0",
                "memory": "0x",
                "memSize": 2144,
                "stack": [
                    "0x9531dc76"
                ],
                "returnData": "0x",
                "storage": null,
                "depth": 1,
                "refund": 0,
                "opName": "STOP",
                "error": ""
            }
        ]
    }
}

Fixes #3775

Type of change

Please delete options that are not relevant.

  • [] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • [] Code refactor or improvement
  • [] Breaking change (fix or feature that would cause a new or changed behavior of existing functionality)
  • [] This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • make test
  • [] fullsync
  • [] Other test (please specify)

Test Configuration:

  • Firmware version:
  • Hardware:
  • Toolchain:
  • SDK:

Checklist:

  • [] My code follows the style guidelines of this project
  • [] I have performed a self-review of my code
  • [] I have commented my code, particularly in hard-to-understand areas
  • [] I have made corresponding changes to the documentation
  • [] My changes generate no new warnings
  • [] I have added tests that prove my fix is effective or that my feature works
  • [] New and existing unit tests pass locally with my changes
  • [] Any dependent changes have been merged and published in downstream modules

@millken millken requested review from Liuhaai, CoderZhi and a team as code owners January 18, 2023 02:51
@codecov
Copy link

codecov bot commented Jan 18, 2023

Codecov Report

Merging #3779 (6ba539c) into master (263ff82) will increase coverage by 0.89%.
The diff coverage is 79.69%.

❗ Current head 6ba539c differs from pull request most recent head 44918bb. Consider uploading reports for the commit 44918bb to get more accurate results

@@            Coverage Diff             @@
##           master    #3779      +/-   ##
==========================================
+ Coverage   74.47%   75.36%   +0.89%     
==========================================
  Files         269      303      +34     
  Lines       23925    25910    +1985     
==========================================
+ Hits        17818    19528    +1710     
- Misses       5174     5359     +185     
- Partials      933     1023      +90     
Impacted Files Coverage Δ
action/actctx.go 90.62% <ø> (+6.25%) ⬆️
action/action.go 82.35% <ø> (ø)
action/action_deserializer.go 57.14% <ø> (ø)
action/candidate_update.go 88.88% <0.00%> (-4.14%) ⬇️
action/consignment_transfer.go 90.41% <ø> (ø)
action/const.go 100.00% <ø> (ø)
action/execution.go 83.78% <ø> (ø)
action/grantreward.go 68.57% <ø> (ø)
action/protocol/account/protocol.go 86.90% <ø> (ø)
action/protocol/dock.go 100.00% <ø> (ø)
... and 284 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@@ -1582,3 +1587,29 @@ func (core *coreService) SyncingProgress() (uint64, uint64, uint64) {
startingHeight, currentHeight, targetHeight, _ := core.bs.SyncStatus()
return startingHeight, currentHeight, targetHeight
}

// TraceTransaction returns the trace result of transaction
func (core *coreService) TraceTransaction(ctx context.Context, actHash string, config *logger.Config) (retval []byte, receipt *action.Receipt, traces *logger.StructLogger, err error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grpcserver.TraceTransactionStructLogs should be integrated with this func

@@ -75,6 +80,28 @@ type (
CurrentBlock string `json:"currentBlock"`
HighestBlock string `json:"highestBlock"`
}
structLog struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if custom marshalling is used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, structLog = logger.StructLog, but logger.StructLog ignored json field storage, web3 API needs to export it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could be done in MarshalJSON()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is no need to implement marshalJSON here, the structLog field can already be automatically marshaled inside. use interface{} is harder to understand

@Liuhaai
Copy link
Member

Liuhaai commented Jan 18, 2023

add test for the new api

api/coreservice.go Outdated Show resolved Hide resolved
api/coreservice.go Outdated Show resolved Hide resolved
api/web3server.go Outdated Show resolved Hide resolved
@Liuhaai
Copy link
Member

Liuhaai commented Jan 20, 2023

add test for the code in coreservice.go

@sonarcloud
Copy link

sonarcloud bot commented Feb 17, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
5.7% 5.7% Duplication

@millken millken merged commit 043e7f8 into iotexproject:master Feb 17, 2023
@millken millken deleted the issue3775 branch February 17, 2023 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[api] implement web3 API debug_traceTransaction
3 participants